﻿create PROCEDURE Sync.SP_CommitteeBankAccountMainBranchDepositAttachments_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[CommitteeBankAccountMainBranchDepositAttachmentID],
		g.[CommitteeBankAccountMainBranchDepositID],g.[Attachment],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[CommitteeBankAccountMainBranchDepositAttachments] g RIGHT JOIN Sync.CommitteeBankAccountMainBranchDepositAttachments_Tracking t  
    ON t.CommitteeBankAccountMainBranchDepositAttachmentID = g.CommitteeBankAccountMainBranchDepositAttachmentID 
    join CommitteeBankAccountMainBranchDeposites cbad on cbad.CommitteeBankAccountMainBranchDepositID = g.CommitteeBankAccountMainBranchDepositID
	join CommitteeBankAccount cba on cba.CommitteeBankAccountID = cbad.CommitteeBankAccountID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cba.CommitteeID = @FilterdColumn))
    END











